<?php
session_start();
$pfadTiefe = str_replace($_SERVER['DOCUMENT_ROOT'], "", dirname(__FILE__)."/" ); // alle nötigen PHP funktionen einfügen
$slashCount = substr_count($pfadTiefe, '/'); // Zählen wieviele Slashes drinne sind
$ebeneTiefer = "";
for($i=0; $i<$slashCount; $i++){ // für jeden slash eine ebene tiefergehen
	$ebeneTiefer .= DIRECTORY_SEPARATOR . '..';
}

$pfad = dirname(__FILE__).$ebeneTiefer;
require_once($pfad."/inc/inc_general_php_functions_for_ajax.php");

switch($_POST['type']){
	case "ladder":
		switch($_POST['mode']){
			case "loadLadderDataTable":
				$SingleLadder = new SingleLadder();
				$ret = $SingleLadder->loadLadderDataTable($_POST['ID'], $_POST['MatchModeID'], $smarty);
				break;
			case "getGeneralLadderPlayers":
				$SingleLadder = new SingleLadder();
				$ret = $SingleLadder->getGeneralLadderPlayers($_POST['ID'], $_POST['reload'], $smarty);
				break;
			case "getBestPlayersFetchedData":
				$SingleLadder = new SingleLadder();
				$ret = $SingleLadder->getBestPlayersFetchedData($smarty, $_POST['mmID']);
				break;
		}

	case "test":
		switch($_POST['mode']){

			case "handleFakeLogin":
				$TestLogin = new TestLogin();
				$ret = $TestLogin->handleFakeLogin($_POST['ID']);
				break;
		}
		break;
	case "matchTeams":
		switch($_POST['mode']){

			case "cleanMatchTeamsOfPlayer":
				$MatchTeams = new MatchTeams();
				$ret = $MatchTeams->cleanMatchTeamsOfPlayer();
				break;
			case "checkAlreadyInMatchTeams":
				$MatchTeams = new MatchTeams();
				$ret = $MatchTeams->checkIfPlayerAlreadyInMatchTeams();
				break;
		}
break;
case "login":
	switch($_POST['mode']){

		case "handleLogout":
			$Login = new Login();
			$ret = $Login->handleLogout();
			break;
	}
	break;
case "user":
	switch($_POST['mode']){

		case "addRegion":
			$User = new User();
			$ret = $User->addRegion($_POST['region']);
			break;
		case "getAllUser":
			$User = new User();
			$ret = $User->getAllUser($_POST['alsoSelf'], $_POST['query'], $_POST['typeahead']);
			break;
		case "fetchUserTable":
			$User = new User();
			$ret = $User->fetchUserTable($_POST['data'], $smarty);
			break;
	}
	break;
case "queue":
	switch($_POST['mode']){

		case "joinSingleQueue":
			$SingleQueue = new SingleQueue();
			$ret = $SingleQueue->joinQueue();
			break;
		case "joinSingleQueue2":
			$SingleQueue = new SingleQueue();
			$ret = $SingleQueue->joinQueue2($_POST['modi'], $_POST['region']);
			break;
		case "leaveQueue":
			$Queue = new Queue();
			$ret = $Queue->leaveQueue();
			break;
		case "leaveQueue2":
			$Queue = new Queue();
			$ret = $Queue->leaveQueue2();
			break;
		case "updateForceSearch":
			$Queue = new Queue();
			$ret = $Queue->updateForceSearch($_POST['forceSearch']);
			break;
		case "kickAllPlayersOutOfQueue":
			$Queue = new Queue();
			$ret = $Queue->kickAllPlayersOutOfQueue($_POST['ID'], $_POST['RS']);
			break;
	}

	break;
case "matchmaking":
	switch($_POST['mode']){
		case "search":
			$Matchmaking = new Matchmaking();
			$ret = $Matchmaking->search($_POST['nr'], $_POST['leave']);
			break;
		case "singleQueueSearch":
			$Matchmaking = new Matchmaking();
			$ret = $Matchmaking->singleQueueSearch($_POST['modi'], $_POST['region'], $_POST["forceSearch"]);
			break;
		case "cleanDBMatchmaking":
			$Matchmaking = new Matchmaking();
			$ret = $Matchmaking->cleanDBMatchmaking($_POST['ID']);
			break;
	}
	break;

case "match":
	switch($_POST['mode']){
		case "accept":
			$Match = new Match();
			$ret = $Match->acceptMatch($_POST['ID']);
			break;
		case "decline":
			$Match = new Match();
			$ret = $Match->declineMatch($_POST['ID']);
			break;
		case "checkAllReadyForMatch":
			$Match = new Match();
			$ret = $Match->checkAllReadyForMatch($_POST['ID']);
			$SmartyFetch = new SmartyFetch();
			$htmlRet = $SmartyFetch->fetchWaitingForOtherPlayersTPL($smarty, $ret['data']);
			$ret['html'] = $htmlRet['data'];
			break;
		case "deleteCreatedMatch": 		$Match = new Match();
		$ret = $Match->deleteCreatedMatch($_POST['ID']);
		break;
		case "submitResult": 			$Match = new Match();
		$ret = $Match->submitResult($_POST['value'], $_POST['ID'], $_POST['screenshot'], $_POST['leaver']);
		break;
		case "saveMatchDetails": 		$Match = new Match();
		$ret = $Match->saveMatchDetails($_POST['ID']);
		break;
		case "cancelMatch":
			$Match = new Match();
			$ret = $Match->cancelMatch($_POST['ID'], $_POST['array'], $_POST['reason']);
			break;
		case "cancelMatchHard":
			$Match = new Match();
			$ret = $Match->cancelMatchHard($_POST['ID']);
			break;
		case "getLastPlayedMatches":
			$Match = new Match();
			$ret = $Match->getLastPlayedMatches($_POST['mmID'], $smarty);
			break;
	}
	break;
case "matchDetails":
	switch($_POST['mode']){
		case "checkForStrangeSubmissions":
			$MatchDetails = new MatchDetails();
			$ret = $MatchDetails->checkForStrangeSubmissions($_POST['ID']);
			break;
		case "getGeneralWinRateTrendData":
			$MatchDetails = new MatchDetails();
			$ret = $MatchDetails->getGeneralWinRateTrendData($_SESSION['tmp']['steamID']);
			break;
		case "getFullGeneralWinRateTrendData":
			$MatchDetails = new MatchDetails();
			$ret = $MatchDetails->getGeneralWinRateTrendData($_SESSION['tmp']['steamID'], "*");
			break;
		case "getEloHistoryData":
			$MatchDetails = new MatchDetails();
			$ret = $MatchDetails->getEloHistoryData($_POST['matchmode'], $_POST['matchtype'], $_POST['count'], $_POST['ID']);
			break;
		case "deleteMatchDetails":
			$MatchDetails = new MatchDetails();
			$ret = $MatchDetails->deleteMatchDetails($_POST['ID']);
			break;
				
	}
	break;
case "uploads":
	switch($_POST['mode']){
		case "moveScreenshotFile":
			$Uploads = new Uploads();
			$steamID = $_SESSION['user']["steamID"];
			$ret = $Uploads->moveScreenshotFile($_POST['ID'], $steamID, $_POST['fileName']);
			break;
	}

	break;
case "chat":
	switch($_POST['mode']){
		case "matchChat":
			$Chat = new Chat();
			$ret = $Chat->handleChat($_POST['function'], $_POST['state'], $_POST['text'], $_POST['file'], $_POST['message'], $smarty);
			break;
	}

	break;
case "userElo":
	switch($_POST['mode']){
		case "getEloRoseData":
			$UserElo = new UserElo();
			$ret = $UserElo->getEloRoseData($_POST['sID']);
			break;
	}
	break;
case "MatchDetailsHostLobby":
	switch($_POST['mode']){
		case "setLobbyHostForMatch":
			$MatchDetailsHostLobby = new MatchDetailsHostLobby();
			$ret = $MatchDetailsHostLobby->setLobbyHostForMatch($_POST['ID']);
			break;
		case "cleanHostForMatch":
			$MatchDetailsHostLobby = new MatchDetailsHostLobby();
			$ret = $MatchDetailsHostLobby->cleanHostForMatch($_POST['ID']);
			break;
	}

	break;
case "UserVotes":
	switch($_POST['mode']){
		case "insertVote":
			$UserVotes = new UserVotes();
			$ret = $UserVotes->insertVote($_POST['sID'], $_POST['vtID'], $_POST['mID'], $_POST['t']);
			break;
	}
	break;
case "banlist":
	switch($_POST['mode']){
		case "checkForBansOfPlayer":
			$Banlist = new Banlist();
			$ret = $Banlist->checkForBansOfPlayer();
			break;
		case "getCurrentBanDataOfPlayer":
			$Banlist = new Banlist();
			$ret = $Banlist->getCurrentBanDataOfPlayer();
			break;
		case "cleanBansOfPlayer":
			$Banlist = new Banlist();
			$ret = $Banlist->cleanBansOfPlayer();
			break;
	}
	break;
case "group":
	switch($_POST['mode']){
		case "createDuoGroup":
			$Group = new Group();
			$ret = $Group->createDuoGroup($_POST['partnerID']);
			break;
	}
	break;
case "QueueGroup":
	switch($_POST['mode']){
		case "joinQueueAsGroup":
			$SingleQueueGroup = new SingleQueueGroup();
			$ret = $SingleQueueGroup->joinQueueAsGroup($_POST['ID'], $_POST['MM'], $_POST['regions']);
			break;
		case "cleanQueueGroup":
			$SingleQueueGroup = new SingleQueueGroup();
			$ret = $SingleQueueGroup->cleanQueueGroup($_POST['ID']);
			break;
		case "checkIfAlreadyInQueueWithGroup":
			$SingleQueueGroup = new SingleQueueGroup();
			$ret = $SingleQueueGroup->checkIfAlreadyInQueueWithGroup();
			break;
	}
	break;

}
echo json_encode($ret);
?>